package com.yanqu.road.server.cmd.activity.dafuweng;

import com.yanqu.road.entity.activity.dafuweng.DFWConfig;
import com.yanqu.road.pb.monopoly.MonopolyProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.dafuweng.DaFuWengMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.string.StringUtils;

@Cmd(code = GameProtocol.S_DA_FU_WENG_GET_UNION_NEWS, desc = "获取商会情报")
public class DaFuWengGetUnionNewsCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        DFWConfig config = DaFuWengMgr.getDfwConfig();
        if (!ActivityMgr.activityInTime(config.getActivityInfo())) {
            ret = GameErrorCode.E_ACTIVITY_DFW_NO_IN_TIME;
            return;
        }

        String unionUid = player.getUserInfo().getUnionUid();
        if (StringUtils.isNullOrEmpty(unionUid)) {
            MonopolyProto.GetUnionNewsRespMsg.Builder builder = MonopolyProto.GetUnionNewsRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_DA_FU_WENG_GET_UNION_NEWS, builder);
            return;
        }

        MonopolyProto.CrossGetUnionNewsReqMsg.Builder builder = MonopolyProto.CrossGetUnionNewsReqMsg.newBuilder();
        builder.setActivityId(config.getActivityInfo().getActivityId());
        builder.setServerId(player.getUserInfo().getOriginalServerId());
        builder.setUnionUid(unionUid);
        builder.setUserId(player.getUserId());
        player.sendUnionActivityGroupPacket(Protocol.C_CROSS_DA_FU_WENG_GET_UNION_NEWS, builder, config.getActivityInfo().getActivityId());
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            MonopolyProto.GetUnionNewsRespMsg.Builder builder = MonopolyProto.GetUnionNewsRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_DA_FU_WENG_GET_UNION_NEWS, builder);
        }
    }
}
